package com.api.gbhg.luoao.la.action;


import com.api.gbhg.huangwm.dao.YuSuanTiaoZhengDao;
import com.api.gbhg.luoao.la.dao.BudgetModifyDao;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;


import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;


import java.util.List;
import java.util.Map;


public class BudgetModifyAction implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {

        //获取调整项目 和 调整类型 流程requestid
        Map<String, Object> property = BudgetModifyDao.getProperty(requestInfo);
        int formid = requestInfo.getRequestManager().getFormid();
        int billid = requestInfo.getRequestManager().getBillid();

        if (property.get("dzlx").equals("0")){

            RecordSetTrans recordSetTrans = new RecordSetTrans();
            recordSetTrans.setAutoCommit(false);
            Map<String, Object> adjustClass = BudgetModifyDao.getDepartmentBudgetadjustment(recordSetTrans
                    , property.get("requestid").toString(),
                    property.get("dzxm").toString(),"0");

             if (adjustClass.get("result").toString().equals("true")){

                 //同步版本
                 //Boolean bo= VersionFlowUtil2.sysDataToVersion2(requestInfo.getRequestid(),requestInfo.getWorkflowid(),,null);
                 return SUCCESS;
             }else if (adjustClass.get("result").toString().equals("false")){
                 requestInfo.getRequestManager().setMessagecontent(adjustClass.get("mg").toString());
                 requestInfo.getRequestManager().setMessageid("1");
                 return FAILURE_AND_CONTINUE;
             }


        }else if(property.get("dzlx").equals("1")){// 预算追加
            RecordSetTrans recordSetTrans = new RecordSetTrans();
            recordSetTrans.setAutoCommit(false);
            Map<String, Object> adjustClass =BudgetModifyDao.getBudgetSupplement(recordSetTrans
                    ,formid,billid,Util.null2String(property.get("sbdw")));
            if (adjustClass.get("result").toString().equals("true")){
                return SUCCESS;
            }else if (adjustClass.get("result").toString().equals("false")){
                requestInfo.getRequestManager().setMessagecontent(adjustClass.get("mg").toString());
                requestInfo.getRequestManager().setMessageid("1");
                return FAILURE_AND_CONTINUE;
            }


        }else if(property.get("dzlx").equals("2")){ // 预算减少
            RecordSetTrans recordSetTrans = new RecordSetTrans();
            recordSetTrans.setAutoCommit(false);
            Map<String, Object> adjustClass =BudgetModifyDao.getBudgetReduce(recordSetTrans
                    ,formid,billid, Util.null2String(property.get("requestid"))
                    ,Util.null2String(property.get("sbdw")),Util.null2String(property.get("dzxm")));
            if (adjustClass.get("result").toString().equals("true")){
                return SUCCESS;
            }else if (adjustClass.get("result").toString().equals("false")){
                requestInfo.getRequestManager().setMessagecontent(adjustClass.get("mg").toString());
                requestInfo.getRequestManager().setMessageid("1");
                return FAILURE_AND_CONTINUE;
            }
        }

        requestInfo.getRequestManager().setMessagecontent("类型只能为经济分类调整、预算追加、预算减少");
        requestInfo.getRequestManager().setMessageid("1");
        return FAILURE_AND_CONTINUE;
    }
}
